program test

type 
  IntPtr = -> int

var
  intVar, x, y : int
  ptrToIntVar, iPtr : IntPtr

Swap(io a:int io b:int)
  var h:int
begin
  h:=a; a:=b; b:=h
end Swap

SwapViaPointers(in aPtr: IntPtr in bPtr: IntPtr)
  var h:int
begin
  h:=aPtr->; aPtr->:=bPtr->; bPtr->:=h
end SwapViaPointers

begin
  intVar := 10
  ptrToIntVar := AddrOf(in intVar)
  Write(in ptrToIntVar->)
  ptrToIntVar-> := 12
  Write(in ptrToIntVar->)
  
  x:=17; y:=4
  Swap(io x io y)
  Write(in x in "+" in y)
  x:=1; y:=2
  SwapViaPointers(in AddrOf(in x) in AddrOf(in y))
  Write(in x in "+" in y)
  
  iPtr := New(in int)
  if iPtr = null then 
    Write(in "Error! Heap overflow")
    halt
  end
  Write(in iPtr->)
  iPtr-> := 11
  Write(in iPtr->)
  Dispose(in iPtr)
  iPtr := null
  Read()
end
